package com.httpDemo.interceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.HandlerInterceptor;
import org.springframework.web.servlet.ModelAndView;

public class MyInterceptor implements HandlerInterceptor {

	/**
	 * 确定是否放行，在执行controller里面的方法之前调用。
	 * 
	 * @param handler 代表要访问的控制器对象
	 */
	@Override
	public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler)
			throws Exception {
		System.out.println("------------preHandle-------------");
		return true;
	}

	/**
	 * 在controller里面的方法执行之后，进行转发或者重定向之前调用。
	 * 
	 * @param handler      同上
	 * @param modelAndView controller中的方法执行完之后返回的对象
	 */
	@Override
	public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
			ModelAndView modelAndView) throws Exception {
		System.out.println("------------postHandle-------------");
	}

	/**
	 * 页面渲染完成之后调用
	 */
	@Override
	public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
			throws Exception {
		System.out.println("------------afterCompletion-------------");
	}
}
